import sqlite3

from PyQt5.QtCore import Qt, QTimer

from Utils.ChangeMac import SetMac
from Utils.GetDevice import get_netcard
from Utils.GetHost import get_host_ip


def setWindowFlag(self):
    self.setAttribute(Qt.WA_TranslucentBackground)
    self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint | Qt.Tool)


def setInputMask(self):
    self.ip_input.setInputMask("000.000.000.000")
    self.mac_input.setInputMask("HH:HH:HH:HH:HH:HH")


def setBtnConnection(self):
    self.scan_ip.clicked.connect(self.startScanSlot)
    self.arp_btn.clicked.connect(self.getArpMessage)
    self.cls_btn.clicked.connect(self.close)
    self.hide_btn.clicked.connect(self.showMinimized)
    self.big_btn.clicked.connect(self.checkWindowStatus)
    self.chMac_btn.clicked.connect(self.changeMac)
    self.arp_cls_btn.clicked.connect(self.clearArp)
    self.listWidget.itemClicked.connect(self.itemEventDeal)
    self.copyMac_btn.clicked.connect(self.copyMac)
    self.chhdMa_btn.clicked.connect(self.openNetManager)
    self.insert_btn.clicked.connect(self.insertData)
    self.select_btn.clicked.connect(self.selectData)
    self.clear_btn.clicked.connect(self.clearData)
    self.hack_btn.clicked.connect(self.arpSniff)
    self.hackStop_btn.clicked.connect(self.arpSniffStop)


def setTimerConnection(self):
    self.timer_scan = QTimer()
    self.timer_scan.timeout.connect(self.scanIpAddress)
    self.timer_hack = QTimer()
    self.timer_hack.timeout.connect(self.arpSniffThread)


def catchTerminal(self):
    self.timer_terminal = QTimer()
    self.timer_terminal.timeout.connect(self.catchTerminalThreading)
    self.timer_terminal.start(100)


def getCurrentIp(self):
    ip = get_host_ip()
    self.ip_input.setText(str(ip))
    netCard = get_netcard()
    for i in netCard:
        if ip == i[1]:
            self.netCard = i[0]


def setParrten(self):
    self.setMac = SetMac()
    self.tarGetIp = 0
    Msg = [
        'Author: Cilang',
        'AuthorQQ: 1019383856',
        'Gitee: https://gitee.com/OpencvLZG/pyqt-ip-scan-mod-mac',
    ]
    for index, context in enumerate(Msg):
        msg = ''
        msg += str(context)
        self.teminal.append(msg)


def connectDatabase(self):
    self.connect = sqlite3.connect('DataBase/ipArpTable.db')
